﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using Newtonsoft.Json;
using System.Web.Script.Services;
using System.Web.Script.Serialization;
using LiangShuaiService.Repository;

namespace LiangShuaiService
{
    /// <summary>
    /// Summary description for WebService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class WebService : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            //JsonConvert.SerializeObject()
            return "Hello World";
        }

        [WebMethod]
        public void GetCutPartsBankInOrOuts(string actionTypeId)
        {
            Context.Response.Charset = "utf-8";
            Context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
           // Context.Response.Headers.Add("contentType", "application/json");
            Context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            Context.Response.Write(JsonConvert.SerializeObject(new CutPartsBankInOrOutRepository().GetCutPartsBankInOrOuts(Convert.ToInt32(actionTypeId))));
            Context.Response.End(); 
        }

        [WebMethod]
        [ScriptMethod(UseHttpGet = true)]
        public void GetColorList()
        {
            Context.Response.Charset = "utf-8";
            Context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
            Context.Response.Headers.Add("contentType", "application/json");
            Context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            Context.Response.Write(JsonConvert.SerializeObject(new CutPartsBankInOrOutRepository().GetColorList()));
            Context.Response.End();
        }

        [WebMethod]
        [ScriptMethod(UseHttpGet = true)]
        public void GetSizeList()
        {
            Context.Response.Charset = "utf-8";
            Context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
            Context.Response.Headers.Add("contentType", "application/json");
            Context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            Context.Response.Write(JsonConvert.SerializeObject(new CutPartsBankInOrOutRepository().GetSizeList()));
            Context.Response.End();
        }

        [WebMethod]
        [ScriptMethod(UseHttpGet = true)]
        public void GetProviderList()
        {
            Context.Response.Charset = "utf-8";
            Context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
            Context.Response.Headers.Add("contentType", "application/json");
            Context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            Context.Response.Write(JsonConvert.SerializeObject(new CutPartsBankInOrOutRepository().GetProviderList()));
            Context.Response.End();
        }

        [WebMethod]
        [ScriptMethod(UseHttpGet = true)]
        public void GeProdectNameList()
        {
            Context.Response.Charset = "utf-8";
            Context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
            Context.Response.Headers.Add("contentType", "application/json");
            Context.Response.Headers.Add("Access-Control-Allow-Origin","*");
            Context.Response.Write(JsonConvert.SerializeObject(new CutPartsBankInOrOutRepository().GetProductList()));
            Context.Response.End();
        }

        [WebMethod]
        [ScriptMethod(UseHttpGet = true)]
        public void GetStyleList()
        {
            Context.Response.Charset = "utf-8";
            Context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
            Context.Response.Headers.Add("contentType", "application/json");
            Context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            Context.Response.Write(JsonConvert.SerializeObject(new CutPartsBankInOrOutRepository().GetStyleList()));
            Context.Response.End();
        }

        [WebMethod]
        public void GetActionType()
        {
            Context.Response.Charset = "utf-8";
            Context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
            //Context.Response.Headers.Add("contentType", "application/json");
            Context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            Context.Response.Write(JsonConvert.SerializeObject(new CutPartsBankInOrOutRepository().GetActionType()));
            Context.Response.End();
        }
    }
}
